package arrays;

/**
 * @author LiangMu
 * @version \$Id: P19.java, v 0.1, 2023年01月04日 13:42 LiangMu Exp $$
 */
public class P19 {
    public int maxArea(int[] height) {
        int len = height.length;
        if (len < 2) {
            return 0;
        }
        int i1 = 0, i2 = len - 1, area = 0;
        while (i1 < i2) {
            int h1 = height[i1];
            int h2 = height[i2];
            int width = i2 - i1;
            if (h2 < h1) {
                area = Math.max(area, h2 * width);
                --i2;
            } else {
                area = Math.max(area, h1 * width);
                ++i1;
            }
        }
        return area;
    }
}
